#include <iostream>
#include <algorithm>
#include <string>
using namespace std;


int main(){
    freopen("in.txt","r",stdin);
    int n,m;
    string s;
    cin >>n >>m ;
    cin >>s;
    int l=0,r=0,an=0,bn=0,ans=INT32_MIN;
    while(r<n){
       if(s[r]=='a'){
           an++;
       }else{
           bn++;
       }
        if(an<=m||bn<=m){
            r++;
        }else{
          ans=max(ans,r-l);  
          if(s[l]=='a'){
              an--;
              l++;
          }else{
              bn--;
              l++;
          }
          r++;
        }
    }
    cout << ans <<endl;
    return 0;
}